package com.link.base.tencent.corpwx.accounttag.controller;

import com.link.base.tencent.corpwx.accounttag.model.AccountTagGroup;
import com.link.base.tencent.corpwx.accounttag.service.AccountTagGroupService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 客户标签 - 标签组
 *
 * @author 欧阳振强
 * @date 2020-01-02 14:56:55.0
 */
@Controller
@RequestMapping("/link/corpwx/accountTagGroup")
public class AccountTagGroupController extends BasicController<AccountTagGroup> {

    @Resource
    private AccountTagGroupService accountTagGroupService;

    @Override
    public BasicService<AccountTagGroup> getBasicService() throws Exception {
        return accountTagGroupService;
    }

    /**
     * 从企业微信获取标签信息同步到CRM，此方法只会处理企业微信新增标签，不处理更新、删除
     *
     * @author 欧阳振强
     * @date 2020/01/03
     * TODO 需要结合实际业务场景来考虑双向更新的情况下，如何处理处理更新等操作
     */
    @PostMapping(value = "/syncAllCorpTagFromWx", name = "企业微信获取标签信息同步到CRM")
    @ResponseBody
    public Map<String, Object> syncAllCorpTagFromWx(HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            accountTagGroupService.syncAllCorpTagFromWx();
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 删除标签组
     *
     * @author 欧阳振强
     * @date 2020/01/03
     */
    @PostMapping(value = "/delTagGroupById", name = "删除标签组")
    @ResponseBody
    public Map<String, Object> delTagGroupById(@JsonParam AccountTagGroup record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            accountTagGroupService.delTagGroupById(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 同步标签组到企业微信
     *
     * @author 欧阳振强
     * @date 2020/01/03
     */
    @PostMapping(value = "/syncTagGroupToWx", name = "同步标签组到企业微信")
    @ResponseBody
    public Map<String, Object> syncTagGroupToWx(@JsonParam AccountTagGroup record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            accountTagGroupService.syncTagGroupToWx(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

}